﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using GotDotNet.ApplicationBlocks.Data;
namespace ToolsLayer
{
    public sealed class DB
    {
        public static readonly char SplitChar = '$';

        public static string ConnectString = System.Configuration.ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
        //属性的单例实现
        private static AdoHelper _helper = null;
        public static AdoHelper helper
        {
            get
            {
                if (_helper == null)
                    _helper = AdoHelper.CreateHelper("GotDotNet.ApplicationBlocks.Data",
                        System.Configuration.ConfigurationManager.ConnectionStrings["connstring"].ProviderName);
                return _helper;
            }
        }

        public static DataSet ExecuteDataset(string CommandText)
        {
            return helper.ExecuteDataset(ConnectString,CommandType.Text, CommandText);
        }

        public static DataSet ExecuteDataset(string CommandText,params IDataParameter[] paras)
        {
            return helper.ExecuteDataset(ConnectString, CommandType.Text, CommandText, paras);
        }

        public static string ExecuteScalar(string CommandText)
        {
            object ob = helper.ExecuteScalar(ConnectString, CommandType.Text, CommandText);
            return ob == null ? null : ob.ToString();
        }
        public static string ExecuteScalar(string CommandText, params IDataParameter[] paras)
        {
            object ob = helper.ExecuteScalar(ConnectString, CommandType.Text, CommandText, paras);
            return ob == null ? null : ob.ToString();
        }

        public static int ExecuteNonQuery(string CommandText)
        {
            return helper.ExecuteNonQuery(ConnectString, CommandType.Text, CommandText);
        }
        public static DataSet ExecuteProcedure(string proc_name, params IDataParameter[] paralist)
        {
            return helper.ExecuteDataset(ConnectString, CommandType.StoredProcedure, proc_name, paralist);
        }

        public static int RunProcedure(string proc_name,params IDataParameter[] paralist)
        {
            return helper.ExecuteNonQuery(ConnectString,CommandType.StoredProcedure, proc_name, paralist);
        }

        public static IDataReader ExecuteReader(string CommandText)
        {
            return helper.ExecuteReader(ConnectString, CommandType.Text, CommandText);
        }
    }
}
